{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>.container { width:100% !important; }</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "计算完毕\n"
     ]
    }
   ],
   "source": [
    "import pymongo\n",
    "import pandas as pd\n",
    "import matplotlib as plt\n",
    "import json\n",
    "from pandas import Series,DataFrame\n",
    "pd.set_option('display.width', None)  # 设置字符显示宽度\n",
    "pd.set_option('display.max_rows', None)  # 设置显示最大行\n",
    "pd.set_option('display.max_columns', None)  # 设置显示最大行\n",
    "#二行即可搞定画图中文乱码\n",
    "plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签\n",
    "plt.rcParams['axes.unicode_minus']=False #用来正常显示负号\n",
    "from IPython.core.display import display, HTML\n",
    "display(HTML(\"<style>.container { width:100% !important; }</style>\"))\n",
    "\n",
    "#连接数据库\n",
    "client = pymongo.MongoClient('localhost',27017)\n",
    "futures = client.futures2\n",
    "\n",
    "market = futures.market2\n",
    "unit = futures.unit\n",
    "position = futures.position2\n",
    "\n",
    "date = \"202000120\"\n",
    "#查询会员\n",
    "BrokerID='海通期货'\n",
    "# BrokerID='永安期货'\n",
    "#加载数据\n",
    "market = DataFrame(list(market.find({'date': {'$gte': date}})))\n",
    "unit = DataFrame(list(unit.find()))\n",
    "position = DataFrame(list(position.find({'date': {'$gte': date}}))).dropna()\n",
    "\n",
    "# #选择需要显示的字段\n",
    "market = market.copy()\n",
    "# 指数收盘\n",
    "market['cv'] = market.apply(lambda x: x['close'] * x['open_interest'], axis=1)\n",
    "closes = market.groupby(['date', 'variety'])[['cv', 'open_interest']].sum()\n",
    "#待解决问题：根据最小价位变动，给收盘价做五舍四入处理\n",
    "closes['close_index'] = closes['cv'] / closes['open_interest']\n",
    "market = closes.reset_index()[['date','variety','close_index']]\n",
    "\n",
    "unit=unit[[ 'variety','unit']]\n",
    "\n",
    "# #汇总合约\n",
    "data3=position[(position['long_party_name'] == BrokerID)]\n",
    "data3=data3[['date','variety','long_party_name','long_open_interest']]\n",
    "data3=data3.groupby(['date','variety','long_party_name'])[['long_open_interest']].sum()\n",
    "\n",
    "data4=position[(position['short_party_name'] == BrokerID)]\n",
    "data4=data4[['date','variety','short_party_name','short_open_interest']]\n",
    "data4=data4.groupby(['date','variety','short_party_name'])[['short_open_interest']].sum()\n",
    "\n",
    "\n",
    "# #并集\n",
    "data5=pd.merge(data3,data4, on=['date','variety'],how='outer')\n",
    "data5['会员简称']=data5.apply(lambda x: BrokerID,axis=1)\n",
    "data5.tail(100)\n",
    "#nan缺失值填充fillna()为0\n",
    "data5=data5.fillna(0)\n",
    "data5['净持仓']=data5.apply(lambda x: x['long_open_interest']-x['short_open_interest'],axis=1)\n",
    "\n",
    "# df['当日涨幅']=df.apply(lambda x: x['收盘']-x['收盘'].shift(1)-1,axis=1)\n",
    "#选择需要显示的字段\n",
    "data5=data5[['会员简称','long_open_interest','short_open_interest','净持仓']]\n",
    "data5=data5.reset_index(['variety','date'])\n",
    "netpostion=data5.set_index('date')\n",
    "\n",
    "\n",
    "netpostion=data5.pivot_table('净持仓',index='date',columns='variety',fill_value=0)\n",
    "# print(netpostion)\n",
    "#合约价值\n",
    "contractValue=pd.merge(market,unit,how='left',sort=False).drop_duplicates()\n",
    "\n",
    "contractValue['contractValue'] = contractValue.apply(lambda x: x['close_index']*x['unit'],axis=1)\n",
    "contractValue=contractValue[['date','variety','contractValue']]\n",
    "\n",
    "# #值替换replace()\n",
    "# # contractValue=contractValue.replace(['TA'],'PTA')\n",
    "sz=pd.merge(data5,contractValue,on=['date','variety'],how='left')\n",
    "\n",
    "# #净持仓价值\n",
    "sz['净持仓价值']=sz.apply(lambda x: int(x['净持仓']*x['contractValue']/10000),axis=1)\n",
    "sz=sz[['date','variety','会员简称','净持仓价值']]\n",
    "sz=sz.sort_values(by='净持仓价值')\n",
    "sz=sz.pivot_table('净持仓价值',index=['date','会员简称'],columns='variety',fill_value=0)\n",
    "sz=sz.copy()\n",
    "sz['化工板块']=sz[['RU','MA','V','L','PP','BU','TA']].sum(axis=1)\n",
    "sz['油脂板块']=sz[['Y','P','OI']].sum(axis=1)\n",
    "sz['有色板块']=sz[['CU','AL','ZN','NI','PB']].sum(axis=1)\n",
    "sz['黑色板块']=sz[['RB','HC','ZC','J','JM','I']].sum(axis=1)\n",
    "sz['黄金白银']=sz[['AU','AG']].sum(axis=1)\n",
    "sz['工业品']=sz[['CU','AL','ZN','NI','PB','RB','FG','RU','L','V','TA','MA','PP','JM','J','ZC','I','BU','HC','SM','SF','FU']].sum(axis=1)\n",
    "sz['农产品']=sz[['A','C','M','RM','Y','P','OI','CF','SR','JD','CS','AP']].sum(axis=1)\n",
    "sz['商品板块']=sz.sum(axis=1)\n",
    "\n",
    "\n",
    "# chemical=sz.copy()\n",
    "# chemical=chemical[['RU','MA','V','L','PP','BU','TA','商品板块','工业品','化工板块']]\n",
    "# chemical['max']=chemical[['RU','MA','V','L','PP','BU','TA']].idxmax(axis=1)\n",
    "# chemical['min']=chemical[['RU','MA','V','L','PP','BU']].idxmin(axis=1)\n",
    "# chemical['20200120':]\n",
    "# chemical = chemical.reset_index()\n",
    "\n",
    "# # futures = client.futures\n",
    "# # flows = futures.chemical\n",
    "# # flows.insert(json.loads(chemical.T.to_json()).values())\n",
    "print(\"计算完毕\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>variety</th>\n",
       "      <th>RU</th>\n",
       "      <th>MA</th>\n",
       "      <th>V</th>\n",
       "      <th>L</th>\n",
       "      <th>PP</th>\n",
       "      <th>BU</th>\n",
       "      <th>TA</th>\n",
       "      <th>商品板块</th>\n",
       "      <th>工业品</th>\n",
       "      <th>化工板块</th>\n",
       "      <th>max</th>\n",
       "      <th>min</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th>会员简称</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20200120</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-73827</td>\n",
       "      <td>49429</td>\n",
       "      <td>-8052</td>\n",
       "      <td>13056</td>\n",
       "      <td>-12471</td>\n",
       "      <td>20610</td>\n",
       "      <td>39034</td>\n",
       "      <td>1008142</td>\n",
       "      <td>9220</td>\n",
       "      <td>27779</td>\n",
       "      <td>MA</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200121</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-38453</td>\n",
       "      <td>-18407</td>\n",
       "      <td>-4455</td>\n",
       "      <td>24644</td>\n",
       "      <td>-43773</td>\n",
       "      <td>18383</td>\n",
       "      <td>0</td>\n",
       "      <td>79942</td>\n",
       "      <td>-120182</td>\n",
       "      <td>-62061</td>\n",
       "      <td>L</td>\n",
       "      <td>PP</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200122</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-28803</td>\n",
       "      <td>-33581</td>\n",
       "      <td>-5444</td>\n",
       "      <td>22154</td>\n",
       "      <td>-38909</td>\n",
       "      <td>16145</td>\n",
       "      <td>0</td>\n",
       "      <td>206284</td>\n",
       "      <td>-62259</td>\n",
       "      <td>-68438</td>\n",
       "      <td>L</td>\n",
       "      <td>PP</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200123</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-42959</td>\n",
       "      <td>1474</td>\n",
       "      <td>-7702</td>\n",
       "      <td>21821</td>\n",
       "      <td>-32251</td>\n",
       "      <td>9612</td>\n",
       "      <td>0</td>\n",
       "      <td>286288</td>\n",
       "      <td>-39055</td>\n",
       "      <td>-50005</td>\n",
       "      <td>L</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200203</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-39183</td>\n",
       "      <td>-9866</td>\n",
       "      <td>-16355</td>\n",
       "      <td>0</td>\n",
       "      <td>-29970</td>\n",
       "      <td>9073</td>\n",
       "      <td>0</td>\n",
       "      <td>29517</td>\n",
       "      <td>-56391</td>\n",
       "      <td>-86301</td>\n",
       "      <td>BU</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200204</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-54062</td>\n",
       "      <td>-3462</td>\n",
       "      <td>-16919</td>\n",
       "      <td>0</td>\n",
       "      <td>-18543</td>\n",
       "      <td>0</td>\n",
       "      <td>34759</td>\n",
       "      <td>-3373</td>\n",
       "      <td>83745</td>\n",
       "      <td>-58227</td>\n",
       "      <td>TA</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200205</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-85738</td>\n",
       "      <td>-19588</td>\n",
       "      <td>-17113</td>\n",
       "      <td>16741</td>\n",
       "      <td>-29627</td>\n",
       "      <td>10358</td>\n",
       "      <td>34295</td>\n",
       "      <td>-652475</td>\n",
       "      <td>-177738</td>\n",
       "      <td>-90672</td>\n",
       "      <td>TA</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200206</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-87854</td>\n",
       "      <td>-11527</td>\n",
       "      <td>-19877</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1504</td>\n",
       "      <td>0</td>\n",
       "      <td>-773812</td>\n",
       "      <td>-239639</td>\n",
       "      <td>-120762</td>\n",
       "      <td>L</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200207</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-82573</td>\n",
       "      <td>-18909</td>\n",
       "      <td>-17530</td>\n",
       "      <td>0</td>\n",
       "      <td>-25810</td>\n",
       "      <td>23853</td>\n",
       "      <td>0</td>\n",
       "      <td>-610976</td>\n",
       "      <td>-187515</td>\n",
       "      <td>-120969</td>\n",
       "      <td>BU</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200210</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-88520</td>\n",
       "      <td>3326</td>\n",
       "      <td>-21740</td>\n",
       "      <td>0</td>\n",
       "      <td>-22517</td>\n",
       "      <td>52228</td>\n",
       "      <td>0</td>\n",
       "      <td>-408351</td>\n",
       "      <td>-85296</td>\n",
       "      <td>-77223</td>\n",
       "      <td>BU</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200211</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-91768</td>\n",
       "      <td>4445</td>\n",
       "      <td>-22420</td>\n",
       "      <td>0</td>\n",
       "      <td>-23327</td>\n",
       "      <td>41350</td>\n",
       "      <td>0</td>\n",
       "      <td>-624366</td>\n",
       "      <td>-193617</td>\n",
       "      <td>-91720</td>\n",
       "      <td>BU</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200212</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-69477</td>\n",
       "      <td>-32065</td>\n",
       "      <td>-20386</td>\n",
       "      <td>0</td>\n",
       "      <td>-27263</td>\n",
       "      <td>74193</td>\n",
       "      <td>0</td>\n",
       "      <td>-419411</td>\n",
       "      <td>-65559</td>\n",
       "      <td>-74998</td>\n",
       "      <td>BU</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200213</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-65786</td>\n",
       "      <td>-2080</td>\n",
       "      <td>-18172</td>\n",
       "      <td>0</td>\n",
       "      <td>-27734</td>\n",
       "      <td>74312</td>\n",
       "      <td>0</td>\n",
       "      <td>-733646</td>\n",
       "      <td>-173239</td>\n",
       "      <td>-39460</td>\n",
       "      <td>BU</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200214</th>\n",
       "      <th>海通期货</th>\n",
       "      <td>-59955</td>\n",
       "      <td>12717</td>\n",
       "      <td>-18746</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>76497</td>\n",
       "      <td>0</td>\n",
       "      <td>-644400</td>\n",
       "      <td>-82226</td>\n",
       "      <td>10513</td>\n",
       "      <td>BU</td>\n",
       "      <td>RU</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "variety           RU     MA      V      L     PP     BU     TA     商品板块  \\\n",
       "date     会员简称                                                             \n",
       "20200120 海通期货 -73827  49429  -8052  13056 -12471  20610  39034  1008142   \n",
       "20200121 海通期货 -38453 -18407  -4455  24644 -43773  18383      0    79942   \n",
       "20200122 海通期货 -28803 -33581  -5444  22154 -38909  16145      0   206284   \n",
       "20200123 海通期货 -42959   1474  -7702  21821 -32251   9612      0   286288   \n",
       "20200203 海通期货 -39183  -9866 -16355      0 -29970   9073      0    29517   \n",
       "20200204 海通期货 -54062  -3462 -16919      0 -18543      0  34759    -3373   \n",
       "20200205 海通期货 -85738 -19588 -17113  16741 -29627  10358  34295  -652475   \n",
       "20200206 海通期货 -87854 -11527 -19877      0      0  -1504      0  -773812   \n",
       "20200207 海通期货 -82573 -18909 -17530      0 -25810  23853      0  -610976   \n",
       "20200210 海通期货 -88520   3326 -21740      0 -22517  52228      0  -408351   \n",
       "20200211 海通期货 -91768   4445 -22420      0 -23327  41350      0  -624366   \n",
       "20200212 海通期货 -69477 -32065 -20386      0 -27263  74193      0  -419411   \n",
       "20200213 海通期货 -65786  -2080 -18172      0 -27734  74312      0  -733646   \n",
       "20200214 海通期货 -59955  12717 -18746      0      0  76497      0  -644400   \n",
       "\n",
       "variety           工业品    化工板块 max min  \n",
       "date     会员简称                          \n",
       "20200120 海通期货    9220   27779  MA  RU  \n",
       "20200121 海通期货 -120182  -62061   L  PP  \n",
       "20200122 海通期货  -62259  -68438   L  PP  \n",
       "20200123 海通期货  -39055  -50005   L  RU  \n",
       "20200203 海通期货  -56391  -86301  BU  RU  \n",
       "20200204 海通期货   83745  -58227  TA  RU  \n",
       "20200205 海通期货 -177738  -90672  TA  RU  \n",
       "20200206 海通期货 -239639 -120762   L  RU  \n",
       "20200207 海通期货 -187515 -120969  BU  RU  \n",
       "20200210 海通期货  -85296  -77223  BU  RU  \n",
       "20200211 海通期货 -193617  -91720  BU  RU  \n",
       "20200212 海通期货  -65559  -74998  BU  RU  \n",
       "20200213 海通期货 -173239  -39460  BU  RU  \n",
       "20200214 海通期货  -82226   10513  BU  RU  "
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chemical=sz.copy()\n",
    "chemical=chemical[['RU','MA','V','L','PP','BU','TA','商品板块','工业品','化工板块']]\n",
    "chemical['max']=chemical[['RU','MA','V','L','PP','BU','TA']].idxmax(axis=1)\n",
    "chemical['min']=chemical[['RU','MA','V','L','PP','BU']].idxmin(axis=1)\n",
    "chemical['20200120':]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>variety</th>\n",
       "      <th>RB</th>\n",
       "      <th>HC</th>\n",
       "      <th>ZC</th>\n",
       "      <th>J</th>\n",
       "      <th>JM</th>\n",
       "      <th>I</th>\n",
       "      <th>黑色板块</th>\n",
       "      <th>工业品</th>\n",
       "      <th>商品板块</th>\n",
       "      <th>max</th>\n",
       "      <th>min</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th>会员简称</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20200120</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>61480</td>\n",
       "      <td>13122</td>\n",
       "      <td>-6705</td>\n",
       "      <td>-72635</td>\n",
       "      <td>-81901</td>\n",
       "      <td>180395</td>\n",
       "      <td>93756</td>\n",
       "      <td>548184</td>\n",
       "      <td>3785629</td>\n",
       "      <td>I</td>\n",
       "      <td>JM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200121</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>45463</td>\n",
       "      <td>2563</td>\n",
       "      <td>-6203</td>\n",
       "      <td>-60355</td>\n",
       "      <td>-86991</td>\n",
       "      <td>156647</td>\n",
       "      <td>51124</td>\n",
       "      <td>331289</td>\n",
       "      <td>3159165</td>\n",
       "      <td>I</td>\n",
       "      <td>JM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200122</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>70796</td>\n",
       "      <td>5943</td>\n",
       "      <td>-7136</td>\n",
       "      <td>-12976</td>\n",
       "      <td>-81024</td>\n",
       "      <td>116554</td>\n",
       "      <td>92157</td>\n",
       "      <td>474251</td>\n",
       "      <td>4009399</td>\n",
       "      <td>I</td>\n",
       "      <td>JM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200123</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>132688</td>\n",
       "      <td>23694</td>\n",
       "      <td>-5963</td>\n",
       "      <td>-5536</td>\n",
       "      <td>-85961</td>\n",
       "      <td>88158</td>\n",
       "      <td>147080</td>\n",
       "      <td>482264</td>\n",
       "      <td>4075371</td>\n",
       "      <td>RB</td>\n",
       "      <td>JM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200203</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>100266</td>\n",
       "      <td>26720</td>\n",
       "      <td>-30650</td>\n",
       "      <td>44458</td>\n",
       "      <td>-60781</td>\n",
       "      <td>84799</td>\n",
       "      <td>164812</td>\n",
       "      <td>501813</td>\n",
       "      <td>4551624</td>\n",
       "      <td>RB</td>\n",
       "      <td>JM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200204</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>41680</td>\n",
       "      <td>23761</td>\n",
       "      <td>-15079</td>\n",
       "      <td>16160</td>\n",
       "      <td>-49908</td>\n",
       "      <td>-41911</td>\n",
       "      <td>-25297</td>\n",
       "      <td>439182</td>\n",
       "      <td>3927802</td>\n",
       "      <td>RB</td>\n",
       "      <td>JM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200205</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>34373</td>\n",
       "      <td>31593</td>\n",
       "      <td>-37891</td>\n",
       "      <td>35588</td>\n",
       "      <td>-40204</td>\n",
       "      <td>-35175</td>\n",
       "      <td>-11716</td>\n",
       "      <td>572394</td>\n",
       "      <td>4253573</td>\n",
       "      <td>J</td>\n",
       "      <td>JM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200206</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>-4777</td>\n",
       "      <td>30339</td>\n",
       "      <td>-36234</td>\n",
       "      <td>54276</td>\n",
       "      <td>-23809</td>\n",
       "      <td>-64894</td>\n",
       "      <td>-45099</td>\n",
       "      <td>680931</td>\n",
       "      <td>4902014</td>\n",
       "      <td>J</td>\n",
       "      <td>I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200207</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>-53010</td>\n",
       "      <td>31144</td>\n",
       "      <td>-61079</td>\n",
       "      <td>47235</td>\n",
       "      <td>-22509</td>\n",
       "      <td>-75900</td>\n",
       "      <td>-134119</td>\n",
       "      <td>539932</td>\n",
       "      <td>4189031</td>\n",
       "      <td>J</td>\n",
       "      <td>I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200210</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>-38085</td>\n",
       "      <td>26028</td>\n",
       "      <td>-39661</td>\n",
       "      <td>54205</td>\n",
       "      <td>-688</td>\n",
       "      <td>-142634</td>\n",
       "      <td>-140835</td>\n",
       "      <td>520796</td>\n",
       "      <td>3990794</td>\n",
       "      <td>J</td>\n",
       "      <td>I</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200211</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>3788</td>\n",
       "      <td>13869</td>\n",
       "      <td>-28162</td>\n",
       "      <td>40661</td>\n",
       "      <td>11099</td>\n",
       "      <td>-2380</td>\n",
       "      <td>38875</td>\n",
       "      <td>729668</td>\n",
       "      <td>4597509</td>\n",
       "      <td>J</td>\n",
       "      <td>ZC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200212</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>-18705</td>\n",
       "      <td>18600</td>\n",
       "      <td>-36635</td>\n",
       "      <td>60845</td>\n",
       "      <td>16631</td>\n",
       "      <td>40840</td>\n",
       "      <td>81576</td>\n",
       "      <td>778554</td>\n",
       "      <td>4542623</td>\n",
       "      <td>J</td>\n",
       "      <td>ZC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200213</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>-57234</td>\n",
       "      <td>15845</td>\n",
       "      <td>-40102</td>\n",
       "      <td>42773</td>\n",
       "      <td>8522</td>\n",
       "      <td>103668</td>\n",
       "      <td>73472</td>\n",
       "      <td>746448</td>\n",
       "      <td>4218247</td>\n",
       "      <td>I</td>\n",
       "      <td>RB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200214</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>-75433</td>\n",
       "      <td>16913</td>\n",
       "      <td>-38274</td>\n",
       "      <td>21210</td>\n",
       "      <td>6784</td>\n",
       "      <td>223559</td>\n",
       "      <td>154759</td>\n",
       "      <td>831695</td>\n",
       "      <td>4584511</td>\n",
       "      <td>I</td>\n",
       "      <td>RB</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "variety            RB     HC     ZC      J     JM       I    黑色板块     工业品  \\\n",
       "date     会员简称                                                               \n",
       "20200120 永安期货   61480  13122  -6705 -72635 -81901  180395   93756  548184   \n",
       "20200121 永安期货   45463   2563  -6203 -60355 -86991  156647   51124  331289   \n",
       "20200122 永安期货   70796   5943  -7136 -12976 -81024  116554   92157  474251   \n",
       "20200123 永安期货  132688  23694  -5963  -5536 -85961   88158  147080  482264   \n",
       "20200203 永安期货  100266  26720 -30650  44458 -60781   84799  164812  501813   \n",
       "20200204 永安期货   41680  23761 -15079  16160 -49908  -41911  -25297  439182   \n",
       "20200205 永安期货   34373  31593 -37891  35588 -40204  -35175  -11716  572394   \n",
       "20200206 永安期货   -4777  30339 -36234  54276 -23809  -64894  -45099  680931   \n",
       "20200207 永安期货  -53010  31144 -61079  47235 -22509  -75900 -134119  539932   \n",
       "20200210 永安期货  -38085  26028 -39661  54205   -688 -142634 -140835  520796   \n",
       "20200211 永安期货    3788  13869 -28162  40661  11099   -2380   38875  729668   \n",
       "20200212 永安期货  -18705  18600 -36635  60845  16631   40840   81576  778554   \n",
       "20200213 永安期货  -57234  15845 -40102  42773   8522  103668   73472  746448   \n",
       "20200214 永安期货  -75433  16913 -38274  21210   6784  223559  154759  831695   \n",
       "\n",
       "variety           商品板块 max min  \n",
       "date     会员简称                   \n",
       "20200120 永安期货  3785629   I  JM  \n",
       "20200121 永安期货  3159165   I  JM  \n",
       "20200122 永安期货  4009399   I  JM  \n",
       "20200123 永安期货  4075371  RB  JM  \n",
       "20200203 永安期货  4551624  RB  JM  \n",
       "20200204 永安期货  3927802  RB  JM  \n",
       "20200205 永安期货  4253573   J  JM  \n",
       "20200206 永安期货  4902014   J   I  \n",
       "20200207 永安期货  4189031   J   I  \n",
       "20200210 永安期货  3990794   J   I  \n",
       "20200211 永安期货  4597509   J  ZC  \n",
       "20200212 永安期货  4542623   J  ZC  \n",
       "20200213 永安期货  4218247   I  RB  \n",
       "20200214 永安期货  4584511   I  RB  "
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "黑色板块=sz.copy()\n",
    "黑色板块=黑色板块[['RB','HC','ZC','J','JM','I','黑色板块','工业品','商品板块']] \n",
    "黑色板块['max']=黑色板块[['RB','HC','ZC','J','JM','I']].idxmax(axis=1) \n",
    "黑色板块['min']=黑色板块[['RB','HC','ZC','J','JM','I']].idxmin(axis=1)\n",
    "黑色板块['20200120':]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import json\n",
    "# from pymongo import MongoClient\n",
    "# # 连接数据库\n",
    "# client = MongoClient('localhost', 27017)\n",
    "# db = client.futures\n",
    "# flow = db.flow\n",
    "# 黑色板块=sz.copy()\n",
    "# 黑色板块=黑色板块[['RB','HC','ZC','J','JM','I','黑色板块','工业品','商品板块']] \n",
    "# 黑色板块['max']=黑色板块[['RB','HC','ZC','J','JM','I']].idxmax(axis=1) \n",
    "# 黑色板块['min']=黑色板块[['RB','HC','ZC','J','JM','I']].idxmin(axis=1)\n",
    "# df = 黑色板块.reset_index()\n",
    "# flow.insert_many(json.loads(df.T.to_json()).values())\n",
    "# print(\"写入OK\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>variety</th>\n",
       "      <th>Y</th>\n",
       "      <th>P</th>\n",
       "      <th>OI</th>\n",
       "      <th>油脂板块</th>\n",
       "      <th>农产品</th>\n",
       "      <th>max</th>\n",
       "      <th>min</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th>会员简称</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20200120</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>395777</td>\n",
       "      <td>147491</td>\n",
       "      <td>12585</td>\n",
       "      <td>555853</td>\n",
       "      <td>868632</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200121</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>409360</td>\n",
       "      <td>103004</td>\n",
       "      <td>13769</td>\n",
       "      <td>526133</td>\n",
       "      <td>875730</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200122</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>421335</td>\n",
       "      <td>161131</td>\n",
       "      <td>14365</td>\n",
       "      <td>596831</td>\n",
       "      <td>1028617</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200123</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>448641</td>\n",
       "      <td>128137</td>\n",
       "      <td>17098</td>\n",
       "      <td>593876</td>\n",
       "      <td>1002939</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200203</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>354640</td>\n",
       "      <td>58192</td>\n",
       "      <td>13001</td>\n",
       "      <td>425833</td>\n",
       "      <td>979867</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200204</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>282397</td>\n",
       "      <td>37160</td>\n",
       "      <td>4821</td>\n",
       "      <td>324378</td>\n",
       "      <td>892836</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200205</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>278061</td>\n",
       "      <td>48414</td>\n",
       "      <td>7889</td>\n",
       "      <td>334364</td>\n",
       "      <td>821803</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200206</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>278388</td>\n",
       "      <td>105875</td>\n",
       "      <td>2904</td>\n",
       "      <td>387167</td>\n",
       "      <td>956192</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200207</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>239973</td>\n",
       "      <td>92334</td>\n",
       "      <td>37447</td>\n",
       "      <td>369754</td>\n",
       "      <td>928700</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200210</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>238261</td>\n",
       "      <td>50891</td>\n",
       "      <td>40894</td>\n",
       "      <td>330046</td>\n",
       "      <td>862133</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200211</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>224937</td>\n",
       "      <td>106644</td>\n",
       "      <td>42757</td>\n",
       "      <td>374338</td>\n",
       "      <td>770375</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200212</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>180979</td>\n",
       "      <td>89257</td>\n",
       "      <td>39709</td>\n",
       "      <td>309945</td>\n",
       "      <td>728994</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200213</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>186807</td>\n",
       "      <td>57908</td>\n",
       "      <td>43298</td>\n",
       "      <td>288013</td>\n",
       "      <td>671274</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200214</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>187520</td>\n",
       "      <td>54327</td>\n",
       "      <td>41808</td>\n",
       "      <td>283655</td>\n",
       "      <td>700597</td>\n",
       "      <td>Y</td>\n",
       "      <td>OI</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "variety             Y       P     OI    油脂板块      农产品 max min\n",
       "date     会员简称                                                \n",
       "20200120 永安期货  395777  147491  12585  555853   868632   Y  OI\n",
       "20200121 永安期货  409360  103004  13769  526133   875730   Y  OI\n",
       "20200122 永安期货  421335  161131  14365  596831  1028617   Y  OI\n",
       "20200123 永安期货  448641  128137  17098  593876  1002939   Y  OI\n",
       "20200203 永安期货  354640   58192  13001  425833   979867   Y  OI\n",
       "20200204 永安期货  282397   37160   4821  324378   892836   Y  OI\n",
       "20200205 永安期货  278061   48414   7889  334364   821803   Y  OI\n",
       "20200206 永安期货  278388  105875   2904  387167   956192   Y  OI\n",
       "20200207 永安期货  239973   92334  37447  369754   928700   Y  OI\n",
       "20200210 永安期货  238261   50891  40894  330046   862133   Y  OI\n",
       "20200211 永安期货  224937  106644  42757  374338   770375   Y  OI\n",
       "20200212 永安期货  180979   89257  39709  309945   728994   Y  OI\n",
       "20200213 永安期货  186807   57908  43298  288013   671274   Y  OI\n",
       "20200214 永安期货  187520   54327  41808  283655   700597   Y  OI"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "oil=sz.copy()\n",
    "oil=oil[['Y','P','OI','油脂板块','农产品']]\n",
    "oil['max']=oil[['Y','P','OI']].idxmax(axis=1) \n",
    "oil['min']=oil[['Y','P','OI']].idxmin(axis=1)\n",
    "oil['20200120':]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>variety</th>\n",
       "      <th>CU</th>\n",
       "      <th>AL</th>\n",
       "      <th>ZN</th>\n",
       "      <th>NI</th>\n",
       "      <th>PB</th>\n",
       "      <th>有色板块</th>\n",
       "      <th>工业品</th>\n",
       "      <th>商品板块</th>\n",
       "      <th>max</th>\n",
       "      <th>min</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th>会员简称</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20200120</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>408192</td>\n",
       "      <td>34245</td>\n",
       "      <td>-28991</td>\n",
       "      <td>-68520</td>\n",
       "      <td>154</td>\n",
       "      <td>345080</td>\n",
       "      <td>548184</td>\n",
       "      <td>3785629</td>\n",
       "      <td>CU</td>\n",
       "      <td>NI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200121</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>316717</td>\n",
       "      <td>14880</td>\n",
       "      <td>-51847</td>\n",
       "      <td>-75761</td>\n",
       "      <td>-165</td>\n",
       "      <td>203824</td>\n",
       "      <td>331289</td>\n",
       "      <td>3159165</td>\n",
       "      <td>CU</td>\n",
       "      <td>NI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200122</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>384698</td>\n",
       "      <td>10882</td>\n",
       "      <td>-69517</td>\n",
       "      <td>-51014</td>\n",
       "      <td>1386</td>\n",
       "      <td>276435</td>\n",
       "      <td>474251</td>\n",
       "      <td>4009399</td>\n",
       "      <td>CU</td>\n",
       "      <td>ZN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200123</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>365854</td>\n",
       "      <td>16916</td>\n",
       "      <td>-48180</td>\n",
       "      <td>-88079</td>\n",
       "      <td>-460</td>\n",
       "      <td>246051</td>\n",
       "      <td>482264</td>\n",
       "      <td>4075371</td>\n",
       "      <td>CU</td>\n",
       "      <td>NI</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200203</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>255283</td>\n",
       "      <td>24019</td>\n",
       "      <td>-42289</td>\n",
       "      <td>-17458</td>\n",
       "      <td>-370</td>\n",
       "      <td>219185</td>\n",
       "      <td>501813</td>\n",
       "      <td>4551624</td>\n",
       "      <td>CU</td>\n",
       "      <td>ZN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200204</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>327963</td>\n",
       "      <td>17149</td>\n",
       "      <td>-34880</td>\n",
       "      <td>-667</td>\n",
       "      <td>-623</td>\n",
       "      <td>308942</td>\n",
       "      <td>439182</td>\n",
       "      <td>3927802</td>\n",
       "      <td>CU</td>\n",
       "      <td>ZN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200205</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>329198</td>\n",
       "      <td>6097</td>\n",
       "      <td>-28484</td>\n",
       "      <td>13511</td>\n",
       "      <td>-13735</td>\n",
       "      <td>306587</td>\n",
       "      <td>572394</td>\n",
       "      <td>4253573</td>\n",
       "      <td>CU</td>\n",
       "      <td>ZN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200206</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>374440</td>\n",
       "      <td>10605</td>\n",
       "      <td>-1813</td>\n",
       "      <td>-3035</td>\n",
       "      <td>-8415</td>\n",
       "      <td>371782</td>\n",
       "      <td>680931</td>\n",
       "      <td>4902014</td>\n",
       "      <td>CU</td>\n",
       "      <td>PB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200207</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>338509</td>\n",
       "      <td>13950</td>\n",
       "      <td>-19193</td>\n",
       "      <td>14218</td>\n",
       "      <td>-16900</td>\n",
       "      <td>330584</td>\n",
       "      <td>539932</td>\n",
       "      <td>4189031</td>\n",
       "      <td>CU</td>\n",
       "      <td>ZN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200210</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>350852</td>\n",
       "      <td>16930</td>\n",
       "      <td>-12893</td>\n",
       "      <td>17688</td>\n",
       "      <td>-20879</td>\n",
       "      <td>351698</td>\n",
       "      <td>520796</td>\n",
       "      <td>3990794</td>\n",
       "      <td>CU</td>\n",
       "      <td>PB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200211</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>363778</td>\n",
       "      <td>-8915</td>\n",
       "      <td>-23072</td>\n",
       "      <td>50919</td>\n",
       "      <td>-19272</td>\n",
       "      <td>363438</td>\n",
       "      <td>729668</td>\n",
       "      <td>4597509</td>\n",
       "      <td>CU</td>\n",
       "      <td>ZN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200212</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>363011</td>\n",
       "      <td>13319</td>\n",
       "      <td>-17559</td>\n",
       "      <td>67336</td>\n",
       "      <td>-20996</td>\n",
       "      <td>405111</td>\n",
       "      <td>778554</td>\n",
       "      <td>4542623</td>\n",
       "      <td>CU</td>\n",
       "      <td>PB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200213</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>357643</td>\n",
       "      <td>11188</td>\n",
       "      <td>-11983</td>\n",
       "      <td>52982</td>\n",
       "      <td>-21351</td>\n",
       "      <td>388479</td>\n",
       "      <td>746448</td>\n",
       "      <td>4218247</td>\n",
       "      <td>CU</td>\n",
       "      <td>PB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200214</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>361771</td>\n",
       "      <td>2487</td>\n",
       "      <td>-18111</td>\n",
       "      <td>48051</td>\n",
       "      <td>-20297</td>\n",
       "      <td>373901</td>\n",
       "      <td>831695</td>\n",
       "      <td>4584511</td>\n",
       "      <td>CU</td>\n",
       "      <td>PB</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "variety            CU     AL     ZN     NI     PB    有色板块     工业品     商品板块  \\\n",
       "date     会员简称                                                                \n",
       "20200120 永安期货  408192  34245 -28991 -68520    154  345080  548184  3785629   \n",
       "20200121 永安期货  316717  14880 -51847 -75761   -165  203824  331289  3159165   \n",
       "20200122 永安期货  384698  10882 -69517 -51014   1386  276435  474251  4009399   \n",
       "20200123 永安期货  365854  16916 -48180 -88079   -460  246051  482264  4075371   \n",
       "20200203 永安期货  255283  24019 -42289 -17458   -370  219185  501813  4551624   \n",
       "20200204 永安期货  327963  17149 -34880   -667   -623  308942  439182  3927802   \n",
       "20200205 永安期货  329198   6097 -28484  13511 -13735  306587  572394  4253573   \n",
       "20200206 永安期货  374440  10605  -1813  -3035  -8415  371782  680931  4902014   \n",
       "20200207 永安期货  338509  13950 -19193  14218 -16900  330584  539932  4189031   \n",
       "20200210 永安期货  350852  16930 -12893  17688 -20879  351698  520796  3990794   \n",
       "20200211 永安期货  363778  -8915 -23072  50919 -19272  363438  729668  4597509   \n",
       "20200212 永安期货  363011  13319 -17559  67336 -20996  405111  778554  4542623   \n",
       "20200213 永安期货  357643  11188 -11983  52982 -21351  388479  746448  4218247   \n",
       "20200214 永安期货  361771   2487 -18111  48051 -20297  373901  831695  4584511   \n",
       "\n",
       "variety       max min  \n",
       "date     会员简称          \n",
       "20200120 永安期货  CU  NI  \n",
       "20200121 永安期货  CU  NI  \n",
       "20200122 永安期货  CU  ZN  \n",
       "20200123 永安期货  CU  NI  \n",
       "20200203 永安期货  CU  ZN  \n",
       "20200204 永安期货  CU  ZN  \n",
       "20200205 永安期货  CU  ZN  \n",
       "20200206 永安期货  CU  PB  \n",
       "20200207 永安期货  CU  ZN  \n",
       "20200210 永安期货  CU  PB  \n",
       "20200211 永安期货  CU  ZN  \n",
       "20200212 永安期货  CU  PB  \n",
       "20200213 永安期货  CU  PB  \n",
       "20200214 永安期货  CU  PB  "
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "有色=sz.copy()\n",
    "有色=有色[['CU','AL','ZN','NI','PB','有色板块','工业品','商品板块']]\n",
    "有色['max']=有色[['CU','AL','ZN','NI','PB']].idxmax(axis=1) \n",
    "有色['min']=有色[['CU','AL','ZN','NI','PB']].idxmin(axis=1)\n",
    "有色['20200120':]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>variety</th>\n",
       "      <th>A</th>\n",
       "      <th>C</th>\n",
       "      <th>M</th>\n",
       "      <th>RM</th>\n",
       "      <th>Y</th>\n",
       "      <th>P</th>\n",
       "      <th>OI</th>\n",
       "      <th>CF</th>\n",
       "      <th>SR</th>\n",
       "      <th>JD</th>\n",
       "      <th>CS</th>\n",
       "      <th>AP</th>\n",
       "      <th>农产品</th>\n",
       "      <th>max</th>\n",
       "      <th>min</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th>会员简称</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20200120</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>36466</td>\n",
       "      <td>166246</td>\n",
       "      <td>65968</td>\n",
       "      <td>18616</td>\n",
       "      <td>395777</td>\n",
       "      <td>147491</td>\n",
       "      <td>12585</td>\n",
       "      <td>137361</td>\n",
       "      <td>-27210</td>\n",
       "      <td>-23563</td>\n",
       "      <td>-26792</td>\n",
       "      <td>-34313</td>\n",
       "      <td>868632</td>\n",
       "      <td>Y</td>\n",
       "      <td>AP</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200121</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>31402</td>\n",
       "      <td>180727</td>\n",
       "      <td>103362</td>\n",
       "      <td>14819</td>\n",
       "      <td>409360</td>\n",
       "      <td>103004</td>\n",
       "      <td>13769</td>\n",
       "      <td>165892</td>\n",
       "      <td>-69088</td>\n",
       "      <td>-25583</td>\n",
       "      <td>-22193</td>\n",
       "      <td>-29741</td>\n",
       "      <td>875730</td>\n",
       "      <td>Y</td>\n",
       "      <td>SR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200122</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>31663</td>\n",
       "      <td>206588</td>\n",
       "      <td>73509</td>\n",
       "      <td>21502</td>\n",
       "      <td>421335</td>\n",
       "      <td>161131</td>\n",
       "      <td>14365</td>\n",
       "      <td>232954</td>\n",
       "      <td>-69220</td>\n",
       "      <td>-24640</td>\n",
       "      <td>-17148</td>\n",
       "      <td>-23422</td>\n",
       "      <td>1028617</td>\n",
       "      <td>Y</td>\n",
       "      <td>SR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200123</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>33864</td>\n",
       "      <td>209988</td>\n",
       "      <td>13904</td>\n",
       "      <td>21309</td>\n",
       "      <td>448641</td>\n",
       "      <td>128137</td>\n",
       "      <td>17098</td>\n",
       "      <td>256696</td>\n",
       "      <td>-68317</td>\n",
       "      <td>-29508</td>\n",
       "      <td>-9556</td>\n",
       "      <td>-19317</td>\n",
       "      <td>1002939</td>\n",
       "      <td>Y</td>\n",
       "      <td>SR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200203</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>31666</td>\n",
       "      <td>231572</td>\n",
       "      <td>70920</td>\n",
       "      <td>33616</td>\n",
       "      <td>354640</td>\n",
       "      <td>58192</td>\n",
       "      <td>13001</td>\n",
       "      <td>275920</td>\n",
       "      <td>-34612</td>\n",
       "      <td>-28819</td>\n",
       "      <td>-8340</td>\n",
       "      <td>-17889</td>\n",
       "      <td>979867</td>\n",
       "      <td>Y</td>\n",
       "      <td>SR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200204</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>31218</td>\n",
       "      <td>186617</td>\n",
       "      <td>76298</td>\n",
       "      <td>17153</td>\n",
       "      <td>282397</td>\n",
       "      <td>37160</td>\n",
       "      <td>4821</td>\n",
       "      <td>279643</td>\n",
       "      <td>31311</td>\n",
       "      <td>-25721</td>\n",
       "      <td>-2844</td>\n",
       "      <td>-25217</td>\n",
       "      <td>892836</td>\n",
       "      <td>Y</td>\n",
       "      <td>JD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200205</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>32003</td>\n",
       "      <td>184147</td>\n",
       "      <td>74667</td>\n",
       "      <td>16369</td>\n",
       "      <td>278061</td>\n",
       "      <td>48414</td>\n",
       "      <td>7889</td>\n",
       "      <td>207937</td>\n",
       "      <td>28834</td>\n",
       "      <td>-26481</td>\n",
       "      <td>-4731</td>\n",
       "      <td>-25306</td>\n",
       "      <td>821803</td>\n",
       "      <td>Y</td>\n",
       "      <td>JD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200206</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>31951</td>\n",
       "      <td>181943</td>\n",
       "      <td>84887</td>\n",
       "      <td>1798</td>\n",
       "      <td>278388</td>\n",
       "      <td>105875</td>\n",
       "      <td>2904</td>\n",
       "      <td>267930</td>\n",
       "      <td>55719</td>\n",
       "      <td>-24971</td>\n",
       "      <td>-4248</td>\n",
       "      <td>-25984</td>\n",
       "      <td>956192</td>\n",
       "      <td>Y</td>\n",
       "      <td>AP</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200207</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>30702</td>\n",
       "      <td>164739</td>\n",
       "      <td>91659</td>\n",
       "      <td>10440</td>\n",
       "      <td>239973</td>\n",
       "      <td>92334</td>\n",
       "      <td>37447</td>\n",
       "      <td>255690</td>\n",
       "      <td>60058</td>\n",
       "      <td>-24941</td>\n",
       "      <td>-4043</td>\n",
       "      <td>-25358</td>\n",
       "      <td>928700</td>\n",
       "      <td>CF</td>\n",
       "      <td>AP</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200210</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>22762</td>\n",
       "      <td>184617</td>\n",
       "      <td>91211</td>\n",
       "      <td>-9738</td>\n",
       "      <td>238261</td>\n",
       "      <td>50891</td>\n",
       "      <td>40894</td>\n",
       "      <td>252151</td>\n",
       "      <td>45485</td>\n",
       "      <td>-24252</td>\n",
       "      <td>-4612</td>\n",
       "      <td>-25537</td>\n",
       "      <td>862133</td>\n",
       "      <td>CF</td>\n",
       "      <td>AP</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200211</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>22086</td>\n",
       "      <td>190893</td>\n",
       "      <td>94431</td>\n",
       "      <td>-11007</td>\n",
       "      <td>224937</td>\n",
       "      <td>106644</td>\n",
       "      <td>42757</td>\n",
       "      <td>177753</td>\n",
       "      <td>-25664</td>\n",
       "      <td>-24011</td>\n",
       "      <td>-5822</td>\n",
       "      <td>-22622</td>\n",
       "      <td>770375</td>\n",
       "      <td>Y</td>\n",
       "      <td>SR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200212</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>21979</td>\n",
       "      <td>178815</td>\n",
       "      <td>96644</td>\n",
       "      <td>-1268</td>\n",
       "      <td>180979</td>\n",
       "      <td>89257</td>\n",
       "      <td>39709</td>\n",
       "      <td>188462</td>\n",
       "      <td>-9902</td>\n",
       "      <td>-27531</td>\n",
       "      <td>-7888</td>\n",
       "      <td>-20262</td>\n",
       "      <td>728994</td>\n",
       "      <td>CF</td>\n",
       "      <td>JD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200213</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>21840</td>\n",
       "      <td>178273</td>\n",
       "      <td>85205</td>\n",
       "      <td>-16601</td>\n",
       "      <td>186807</td>\n",
       "      <td>57908</td>\n",
       "      <td>43298</td>\n",
       "      <td>174745</td>\n",
       "      <td>-2241</td>\n",
       "      <td>-26800</td>\n",
       "      <td>-9152</td>\n",
       "      <td>-22008</td>\n",
       "      <td>671274</td>\n",
       "      <td>Y</td>\n",
       "      <td>JD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200214</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>24075</td>\n",
       "      <td>199802</td>\n",
       "      <td>99340</td>\n",
       "      <td>-14540</td>\n",
       "      <td>187520</td>\n",
       "      <td>54327</td>\n",
       "      <td>41808</td>\n",
       "      <td>166916</td>\n",
       "      <td>-2202</td>\n",
       "      <td>-27703</td>\n",
       "      <td>-3780</td>\n",
       "      <td>-24966</td>\n",
       "      <td>700597</td>\n",
       "      <td>C</td>\n",
       "      <td>JD</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "variety            A       C       M     RM       Y       P     OI      CF  \\\n",
       "date     会员简称                                                                \n",
       "20200120 永安期货  36466  166246   65968  18616  395777  147491  12585  137361   \n",
       "20200121 永安期货  31402  180727  103362  14819  409360  103004  13769  165892   \n",
       "20200122 永安期货  31663  206588   73509  21502  421335  161131  14365  232954   \n",
       "20200123 永安期货  33864  209988   13904  21309  448641  128137  17098  256696   \n",
       "20200203 永安期货  31666  231572   70920  33616  354640   58192  13001  275920   \n",
       "20200204 永安期货  31218  186617   76298  17153  282397   37160   4821  279643   \n",
       "20200205 永安期货  32003  184147   74667  16369  278061   48414   7889  207937   \n",
       "20200206 永安期货  31951  181943   84887   1798  278388  105875   2904  267930   \n",
       "20200207 永安期货  30702  164739   91659  10440  239973   92334  37447  255690   \n",
       "20200210 永安期货  22762  184617   91211  -9738  238261   50891  40894  252151   \n",
       "20200211 永安期货  22086  190893   94431 -11007  224937  106644  42757  177753   \n",
       "20200212 永安期货  21979  178815   96644  -1268  180979   89257  39709  188462   \n",
       "20200213 永安期货  21840  178273   85205 -16601  186807   57908  43298  174745   \n",
       "20200214 永安期货  24075  199802   99340 -14540  187520   54327  41808  166916   \n",
       "\n",
       "variety           SR     JD     CS     AP      农产品 max min  \n",
       "date     会员简称                                               \n",
       "20200120 永安期货 -27210 -23563 -26792 -34313   868632   Y  AP  \n",
       "20200121 永安期货 -69088 -25583 -22193 -29741   875730   Y  SR  \n",
       "20200122 永安期货 -69220 -24640 -17148 -23422  1028617   Y  SR  \n",
       "20200123 永安期货 -68317 -29508  -9556 -19317  1002939   Y  SR  \n",
       "20200203 永安期货 -34612 -28819  -8340 -17889   979867   Y  SR  \n",
       "20200204 永安期货  31311 -25721  -2844 -25217   892836   Y  JD  \n",
       "20200205 永安期货  28834 -26481  -4731 -25306   821803   Y  JD  \n",
       "20200206 永安期货  55719 -24971  -4248 -25984   956192   Y  AP  \n",
       "20200207 永安期货  60058 -24941  -4043 -25358   928700  CF  AP  \n",
       "20200210 永安期货  45485 -24252  -4612 -25537   862133  CF  AP  \n",
       "20200211 永安期货 -25664 -24011  -5822 -22622   770375   Y  SR  \n",
       "20200212 永安期货  -9902 -27531  -7888 -20262   728994  CF  JD  \n",
       "20200213 永安期货  -2241 -26800  -9152 -22008   671274   Y  JD  \n",
       "20200214 永安期货  -2202 -27703  -3780 -24966   700597   C  JD  "
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "农产品=sz.copy()\n",
    "农产品=农产品[['A','C','M','RM','Y','P','OI','CF','SR','JD','CS','AP','农产品']]\n",
    "农产品['max']=农产品[['A','C','M','RM','Y','P','OI','CF','SR','JD','CS','AP']].idxmax(axis=1) \n",
    "农产品['min']=农产品[['A','C','M','RM','Y','P','OI','CF','SR','JD','CS','AP']].idxmin(axis=1)\n",
    "农产品['20200120':]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>variety</th>\n",
       "      <th>商品板块</th>\n",
       "      <th>工业品</th>\n",
       "      <th>化工板块</th>\n",
       "      <th>黑色板块</th>\n",
       "      <th>有色板块</th>\n",
       "      <th>农产品</th>\n",
       "      <th>油脂板块</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th>会员简称</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20200120</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>3785629</td>\n",
       "      <td>548184</td>\n",
       "      <td>8474</td>\n",
       "      <td>93756</td>\n",
       "      <td>345080</td>\n",
       "      <td>868632</td>\n",
       "      <td>555853</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200121</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>3159165</td>\n",
       "      <td>331289</td>\n",
       "      <td>5909</td>\n",
       "      <td>51124</td>\n",
       "      <td>203824</td>\n",
       "      <td>875730</td>\n",
       "      <td>526133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200122</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>4009399</td>\n",
       "      <td>474251</td>\n",
       "      <td>39644</td>\n",
       "      <td>92157</td>\n",
       "      <td>276435</td>\n",
       "      <td>1028617</td>\n",
       "      <td>596831</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200123</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>4075371</td>\n",
       "      <td>482264</td>\n",
       "      <td>22052</td>\n",
       "      <td>147080</td>\n",
       "      <td>246051</td>\n",
       "      <td>1002939</td>\n",
       "      <td>593876</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200203</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>4551624</td>\n",
       "      <td>501813</td>\n",
       "      <td>58461</td>\n",
       "      <td>164812</td>\n",
       "      <td>219185</td>\n",
       "      <td>979867</td>\n",
       "      <td>425833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200204</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>3927802</td>\n",
       "      <td>439182</td>\n",
       "      <td>111924</td>\n",
       "      <td>-25297</td>\n",
       "      <td>308942</td>\n",
       "      <td>892836</td>\n",
       "      <td>324378</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200205</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>4253573</td>\n",
       "      <td>572394</td>\n",
       "      <td>225765</td>\n",
       "      <td>-11716</td>\n",
       "      <td>306587</td>\n",
       "      <td>821803</td>\n",
       "      <td>334364</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200206</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>4902014</td>\n",
       "      <td>680931</td>\n",
       "      <td>271083</td>\n",
       "      <td>-45099</td>\n",
       "      <td>371782</td>\n",
       "      <td>956192</td>\n",
       "      <td>387167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200207</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>4189031</td>\n",
       "      <td>539932</td>\n",
       "      <td>260665</td>\n",
       "      <td>-134119</td>\n",
       "      <td>330584</td>\n",
       "      <td>928700</td>\n",
       "      <td>369754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200210</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>3990794</td>\n",
       "      <td>520796</td>\n",
       "      <td>240307</td>\n",
       "      <td>-140835</td>\n",
       "      <td>351698</td>\n",
       "      <td>862133</td>\n",
       "      <td>330046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200211</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>4597509</td>\n",
       "      <td>729668</td>\n",
       "      <td>245429</td>\n",
       "      <td>38875</td>\n",
       "      <td>363438</td>\n",
       "      <td>770375</td>\n",
       "      <td>374338</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200212</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>4542623</td>\n",
       "      <td>778554</td>\n",
       "      <td>192093</td>\n",
       "      <td>81576</td>\n",
       "      <td>405111</td>\n",
       "      <td>728994</td>\n",
       "      <td>309945</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200213</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>4218247</td>\n",
       "      <td>746448</td>\n",
       "      <td>178071</td>\n",
       "      <td>73472</td>\n",
       "      <td>388479</td>\n",
       "      <td>671274</td>\n",
       "      <td>288013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20200214</th>\n",
       "      <th>永安期货</th>\n",
       "      <td>4584511</td>\n",
       "      <td>831695</td>\n",
       "      <td>185362</td>\n",
       "      <td>154759</td>\n",
       "      <td>373901</td>\n",
       "      <td>700597</td>\n",
       "      <td>283655</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "variety           商品板块     工业品    化工板块    黑色板块    有色板块      农产品    油脂板块\n",
       "date     会员简称                                                          \n",
       "20200120 永安期货  3785629  548184    8474   93756  345080   868632  555853\n",
       "20200121 永安期货  3159165  331289    5909   51124  203824   875730  526133\n",
       "20200122 永安期货  4009399  474251   39644   92157  276435  1028617  596831\n",
       "20200123 永安期货  4075371  482264   22052  147080  246051  1002939  593876\n",
       "20200203 永安期货  4551624  501813   58461  164812  219185   979867  425833\n",
       "20200204 永安期货  3927802  439182  111924  -25297  308942   892836  324378\n",
       "20200205 永安期货  4253573  572394  225765  -11716  306587   821803  334364\n",
       "20200206 永安期货  4902014  680931  271083  -45099  371782   956192  387167\n",
       "20200207 永安期货  4189031  539932  260665 -134119  330584   928700  369754\n",
       "20200210 永安期货  3990794  520796  240307 -140835  351698   862133  330046\n",
       "20200211 永安期货  4597509  729668  245429   38875  363438   770375  374338\n",
       "20200212 永安期货  4542623  778554  192093   81576  405111   728994  309945\n",
       "20200213 永安期货  4218247  746448  178071   73472  388479   671274  288013\n",
       "20200214 永安期货  4584511  831695  185362  154759  373901   700597  283655"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "板块=sz.copy()\n",
    "板块=板块[['商品板块','工业品','化工板块','黑色板块','有色板块','农产品','油脂板块']]\n",
    "板块['20200120':]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
